//
//  UIButton+Extension.swift
//  weibo20
//
//  Created by mac on 16/1/17.
//  Copyright © 2016年 tingyuyisheng. All rights reserved.
//

import UIKit

extension UIButton {

	// MARK: - 便利构造函数

	/// 便利构造函数
	///
	/// - parameter imageName:           imageName
	/// - parameter backgroundImageName: backgroundImageName
	///
	/// - returns:
	convenience init(imageName: String, backgroundImageName: String) {
		self.init()

		setImage(UIImage(named: imageName), forState: UIControlState.Normal)
		setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
		setBackgroundImage(UIImage(named: backgroundImageName), forState: UIControlState.Normal)
		setBackgroundImage(UIImage(named: backgroundImageName + "_highlighted"), forState: UIControlState.Highlighted)

		// 会根据背景图片的大小调整尺寸
		sizeToFit()
	}

	/// 便利构造函数
	///
	/// - parameter title:     title
	/// - parameter color:     color
	/// - parameter imageName: imageName
	///
	/// - returns:
	convenience init(title: String, color: UIColor, imageName: String) {

		self.init()
		// 设置背景图片
		setBackgroundImage(UIImage(named: imageName), forState: .Normal)
		// 设置文字大小以及文字颜色
		setTitle(title, forState: .Normal)
		titleLabel?.font = UIFont.systemFontOfSize(14)
		setTitleColor(color, forState: .Normal)
		// 调整大小
		sizeToFit()
	}
}